package com.sh.threadmethod.stopmethod;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class TestStop implements Runnable {
    private volatile boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while (flag) {
            System.out.println("i=" + (++i));
        }
    }

    public void stop() {
        this.flag = false;
    }

    public static void main(String[] args) {
        TestStop testStop = new TestStop();
        Thread thread = new Thread(testStop);
        thread.start();
        for (int i = 0; i < 9900; i++) {
            if (i==9000){
                testStop.stop();
            }
        }

    }
}

